home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 February / PC Plus Super CD (Issue 124) (PCP124-2-97) (February 1997).iso / componen / m4 / vine.kb < prev    next >
Encoding:
Text File  |  1996-01-12  |  10.2 KB  |  365 lines

  1. /*
  2.                         <M.1> V I N E
  3.                          Version 2.1
  4.                 Copyright (c) Teknowledge Inc, 1986
  5.  
  6.                          December 10, 1986
  7. */
  8.  
  9. /*
  10.         This knowledge base contains the same knowledge as WINE,
  11.         but uses logical variables (denoted by capital letters)
  12.         so that syntactically identical rules from the WINE knowledge
  13.         base can be collapsed into a single rule in VINE.
  14.  
  15.         In addition, VINE uses logical variables in conjunction with
  16.         a small database of wines, and a single  'table lookup' rule 
  17.         to find the wines, rather than a separate rule for each wine.
  18. */
  19.  
  20. /*
  21.         The top-level goal of the consultation is 'wine'.
  22. */
  23.  
  24. goal = wine.
  25.  
  26. /* 
  27.    Before the system attempts any inferences, 
  28.    the user's preferences are obtained:
  29. */
  30.  
  31. initialdata = [preferred-color, preferred-body, preferred-sweetness].
  32.  
  33. /* --------------------------- BEST-BODY ------------------------------- */
  34.  
  35. /*
  36.         The following rules use information about the sauce on the meal
  37.         and the meal's tastiness to find the best body for the wine.
  38. */
  39.  
  40. rule-1:  if has-sauce and
  41.             sauce = spicy
  42.          then best-body = full.
  43.  
  44. rule-2:  if tastiness = delicate
  45.          then best-body = light cf 80.
  46.  
  47. rule-3:  if tastiness = average
  48.          then best-body = light cf 30 and
  49.               best-body = medium cf 60 and
  50.               best-body = full cf 30.
  51.  
  52. rule-4:  if tastiness = strong
  53.          then best-body = medium cf 40 and
  54.               best-body = full cf 80.
  55.  
  56. rule-5:  if has-sauce  and
  57.             sauce = cream
  58.          then best-body = medium cf 40 and
  59.               best-body = full cf 60.
  60.  
  61. /* --------------------------------- BEST-COLOR -------------------- */
  62.  
  63. /*
  64.         The following rules use information about the main component
  65.         of the meal and the sauce on the meal to determine the best
  66.         color of wine to accompany the meal.
  67. */
  68.  
  69. rule-6:  if main-component = meat and
  70.             has-veal = no
  71.          then best-color = red cf 90.
  72.         
  73. rule-7:  if main-component = poultry and
  74.             has-turkey = no
  75.          then best-color = white cf 90 and
  76.               best-color = red cf 30.
  77.  
  78. rule-8: if main-component = fish
  79.         then best-color = white.
  80.  
  81. rule-9:  if not(main-component = fish) and
  82.             has-sauce  and
  83.             sauce = tomato
  84.          then best-color = red.
  85.  
  86. rule-10: if main-component = poultry and
  87.             has-turkey
  88.          then best-color = red cf 80 and
  89.               best-color = white cf 50.
  90.  
  91. rule-11: if has-sauce = yes and
  92.             sauce = cream
  93.          then best-color = white cf 40 and
  94.               best-color = red cf -90.
  95.  
  96. /* -------------------------- BEST-SWEETNESS -------------------------- */
  97.  
  98. /*
  99.         The only rule that can help provide information about how sweet
  100.         the recommended wines should be 'fires' when the meal has a sweet
  101.         sauce on it.
  102. */
  103.  
  104. rule-12: if has-sauce  and
  105.             sauce = sweet
  106.          then best-sweetness = sweet cf 90 and
  107.               best-sweetness = medium cf 40.
  108.  
  109. /* ----------------------- DEFAULT-X --------------------------------- */
  110.  
  111. /*
  112.         These default expressions are used when M.1 is unable to find
  113.         values for either best-CHARACTERISTIC or preferred-CHARACTERISTIC.
  114.  
  115.         The single 'noautomaticquestion' entry keeps M.1 from ever asking
  116.         the user to provide a value for a default characteristic.
  117. */
  118.  
  119.  
  120. noautomaticquestion(default-X).
  121.  
  122. default-body = medium.
  123.  
  124. default-color = red cf 50.
  125. default-color = white cf 50.
  126.  
  127. default-sweetness = medium.
  128.  
  129.  
  130.  
  131. /* ----------------------- FEATURE ----------------------------------- */
  132.  
  133. /*
  134.         'Feature' is a special characteristic of wine, currently used
  135.         only to indicate that the meal is spicy.
  136. */
  137.             
  138. multivalued(feature).
  139.  
  140.  
  141. rule-13: if has-sauce  and
  142.             sauce = spicy
  143.          then feature = spiciness.
  144.  
  145. /* ----------------------------- HAS-SAUCE --------------------------- */
  146.  
  147. /*
  148.    We used 'automaticmenu' without 'enumeratedanswers' to get a menu
  149.    of 'legalvals' with no numbers assigned to them.
  150. */
  151.  
  152. question(has-sauce) =  'Does the meal have a sauce on it?'.
  153.  
  154. legalvals(has-sauce) = [yes, no].
  155.  
  156. automaticmenu(has-sauce).
  157.  
  158. /* ---------------------------- HAS-TURKEY ---------------------------- */
  159.  
  160. /*
  161.    We used 'automaticmenu' without 'enumeratedanswers' to get a menu
  162.    of 'legalvals' with no numbers assigned to them.
  163. */
  164.  
  165. question(has-turkey) =  'Does the meal have turkey in it?'.
  166.  
  167. legalvals(has-turkey) = [yes, no].
  168.  
  169. automaticmenu(has-turkey).
  170.  
  171. /* ---------------------------- HAS-VEAL ------------------------------- */
  172.  
  173. /*
  174.    We used 'automaticmenu' without 'enumeratedanswers' to get a menu
  175.    of 'legalvals' with no numbers assigned to them.
  176. */
  177.  
  178. question(has-veal) =  'Does the meal have veal in it?'.
  179.  
  180. legalvals(has-veal) = [yes, no].
  181.  
  182. automaticmenu(has-veal).
  183.  
  184. /* ---------------------------- MAIN-COMPONENT ------------------------- */
  185.  
  186. /*
  187.    The 'question' for main-component contains a more informative menu
  188.    than that produced by the 'automaticmenu' meta-fact.  Note that
  189.    spacing and carriage returns within the question are respected by M.1.
  190. */
  191.  
  192. multivalued(main-component).
  193.  
  194. enumeratedanswers(main-component).
  195.  
  196. automaticmenu(main-component).
  197.  
  198. question(main-component) =
  199.     'What is the main component of the meal?'.
  200.  
  201. legalvals(main-component) = [meat, fish, poultry].
  202.  
  203. /* ----------------------------- PREFERRED-X --------------------------- */
  204.  
  205. /*
  206.    These meta-facts contain logical variables (in capital letters) that
  207.    allow these meta-facts to apply when seeking preferred-color,
  208.    preferred-body, and preferred-sweetness.
  209. */
  210.  
  211. enumeratedanswers(preferred-X).
  212.  
  213. automaticmenu(preferred-X).
  214.  
  215. /* --------------------------- PREFERRED-BODY -------------------------- */
  216.  
  217. multivalued(preferred-body).
  218.  
  219. question(preferred-body) =
  220.   'Do you generally prefer light, medium or full bodied wines?'.
  221.  
  222. legalvals(preferred-body) = [light, medium, full].
  223.  
  224. /* -------------------------- PREFERRED-COLOR -------------------------- */
  225.  
  226. multivalued(preferred-color).
  227.  
  228. question(preferred-color) =
  229.   'Do you generally prefer red or white wines?'.
  230.  
  231. legalvals(preferred-color) = [red, white].
  232.  
  233. /* -------------------------- PREFERRED-SWEETNESS ---------------------- */
  234.  
  235. multivalued(preferred-sweetness).
  236.  
  237. question(preferred-sweetness) =
  238.   'Do you generally prefer dry, medium or sweet wines?'.
  239.  
  240. legalvals(preferred-sweetness) = [dry, medium, sweet].
  241.  
  242.  
  243. /* -------------------------- RECOMMENDED-X ------------------------- */
  244.  
  245. /*
  246.         These rules contain logical variables (in capital letters)
  247.         that make these rules applicable when seeking best-color,
  248.         best-body, and best-sweetness.
  249.  
  250.         If best-CHARACTERISTIC is known, then that is what's recommended.
  251.         If the user's preference about a particular characteristic is known,
  252.         then that's used as the recommended characteristic. If neither
  253.         the best nor the preferred characteristic is known, then a default
  254.         value is used.
  255. */
  256.  
  257. v-rule-1: if best-X = V
  258.          then recommended-X = V.
  259.         
  260. v-rule-2: if best-X is unknown and
  261.              preferred-X = V
  262.          then recommended-X = V.
  263.  
  264. v-rule-3: if best-X is unknown and
  265.              preferred-X is unknown and
  266.              default-X = V
  267.           then recommended-X = V.
  268.  
  269. /* -------------------------- SAUCE ---------------------------------- */
  270.  
  271. /*
  272. 'automaticmenu' and 'enumeratedanswers' are used to generate a
  273. numbered menu of 'legalvals' for this question.
  274. */
  275.  
  276. multivalued(sauce).
  277.  
  278. question(sauce) =
  279.   'What kind of sauce does the meal have?'.
  280.  
  281. legalvals(sauce) = [spicy, sweet, cream, tomato].
  282.  
  283. automaticmenu(sauce).
  284.  
  285. enumeratedanswers(sauce).
  286.  
  287. /* ------------------------- TASTINESS ------------------------------- */
  288.  
  289. multivalued(tastiness).
  290.  
  291. question(tastiness) =
  292.   'Is the flavor of the meal delicate, average or strong?'.
  293.  
  294. legalvals(tastiness) = [delicate, average, strong].
  295.  
  296. /* ----------------------------- WINE ------------------------------ */
  297.  
  298. multivalued(wine).
  299. multivalued(wine(COLOR,BODY,SWEETNESS)).
  300.  
  301. /*
  302. The following rule, with the table entries that follow, replaces the bulk
  303. of the rules from the wine KB that conclude wine:
  304. */
  305.  
  306. v-rule-4: if recommended-color = C and
  307.             recommended-body = B and
  308.             recommended-sweetness = S and
  309.             wine(C,B,S) = W
  310.           then wine = W.
  311.  
  312. /*
  313. The following rule mentions feature, and hence is inconvenient to
  314. replace by a table-entry.
  315. */
  316.  
  317. rule-14: if recommended-color = white and
  318.             recommended-body = full and
  319.             feature = spiciness
  320.         then wine = gewuerztraminer.
  321.  
  322.  
  323. /* ----------------- WINE(COLOR, BODY, SWEETNESS) ------------------ */
  324.  
  325. /* This 'noautomaticquestions' statement ensures that no automatic question
  326.    will be generated for wines not included in this table.
  327. */
  328.  
  329. noautomaticquestion(wine(COLOR,BODY,SWEETNESS)).
  330.  
  331.  
  332. /*
  333. These table entries represent the mapping of attribute triples to specific
  334. wines. Note the use of the variable ANY in some entries to indicate that
  335. a particular attribute doesn't play a role in the selection of that wine:
  336. */
  337.  
  338. wine(red,medium,medium) = gamay.
  339. wine(red,medium,sweet) = gamay.
  340. wine(white,light,dry) = chablis.
  341. wine(white,medium,dry) = 'sauvignon blanc'.
  342. wine(white,medium,dry) = chardonnay.
  343. wine(white,medium,medium) = chardonnay.
  344. wine(white,full,dry) = chardonnay.
  345. wine(white,full,medium) = chardonnay.
  346. wine(white,light,dry) = soave.
  347. wine(white,light,medium) = soave.
  348. wine(white,light,medium) = riesling.
  349. wine(white,light,sweet) = riesling.
  350. wine(white,medium,medium) = riesling.
  351. wine(white,medium,sweet) = riesling.
  352. wine(white,light,medium) = 'chenin blanc'.
  353. wine(white,light,sweet) = 'chenin blanc'.
  354. wine(red,light,ANY) = valpolicella.
  355. wine(red,ANY,dry) = 'cabernet sauvignon'.
  356. wine(red,ANY,dry) = zinfandel.
  357. wine(red,ANY,medium) = 'cabernet sauvignon'.
  358. wine(red,ANY,medium) = zinfandel.
  359. wine(red,medium,medium) = 'pinot noir'.
  360. wine(red,full,ANY) = burgundy.
  361.  
  362. /* ----------------------------------------------------------------------- */
  363.  
  364.  
  365.